#include <iostream>
#include <stdio.h>
#include <string.h>

#define MAXT 3000

using namespace std;

struct Node
{
    int num, time; // 月饼:时刻为t时费用为num；顾客:时刻为t时要num个月饼
} q[MAXT * 4], order[MAXT];

int MonDay[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 每个月的天数

int mon(char *s)
{
    if (strcmp(s, "Jan") == 0)
        return 1;
    if (strcmp(s, "Feb") == 0)
        return 2;
    if (strcmp(s, "Mar") == 0)
        return 3;
    if (strcmp(s, "Apr") == 0)
        return 4;
    if (strcmp(s, "May") == 0)
        return 5;
    if (strcmp(s, "Jun") == 0)
        return 6;
    if (strcmp(s, "Jul") == 0)
        return 7;
    if (strcmp(s, "Aug") == 0)
        return 8;
    if (strcmp(s, "Sep") == 0)
        return 9;
    if (strcmp(s, "Oct") == 0)
        return 10;
    if (strcmp(s, "Nov") == 0)
        return 11;
    if (strcmp(s, "Dec") == 0)
        return 12;
}

bool isLeapYear(int year) // 判定闰年
{
    return year % 4 == 0 && (year % 100 || year % 400 == 0);
}

int getHour(int year, int month, int day, int hour) // 日期化为小时
{
    int tot = 0;
    for (int i = 2000; i < year; i++)
    {
        if (isLeapYear(i))
            tot += 366; // 闰年366天
        else
            tot += 365; // 平常365天
    }
    for (int i = 1; i < month; i++)
    {
        if (isLeapYear(year) && i == 2)
            tot += 29; // 闰年2月29天
        else
            tot += MonDay[i];
    }
    tot += day - 1; // 加上天数
    return tot = tot * 24 + hour;
}

int main()
{
    while (1)
    {
        char s[10];
        int n, m, year, month, day, hour, T, S, cost, h = 0, t = 0, p = 0;
        long long int sum = 0;
        scanf("%d%d", &n, &m);
        if (n == 0 && m == 0)
            return 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%s%d%d%d%d", s, &day, &year, &hour, &order[i].num);
            order[i].time = getHour(year, mon(s), day, hour); // 存入顾客需求，将日期化为小时
        }
        scanf("%d%d", &T, &S);
        for (int i = 0; i < m; i++)
        {
            scanf("%d", &cost);
            while (h < t && q[t - 1].num + S * (i - q[t - 1].time) >= cost)
                t--;                            // 对于第x个订单,其交付日期为j，制作日期为i，保存花费为s,则其总代价为cost[x]+(j-i)*s，维护队尾单调性
            q[t].num = cost, q[t++].time = i;   // 新状态入队
            while (p < n && i == order[p].time) // 处理第p个订单
            {
                while (q[h].time + T < i)
                    h++;                                                  // 加上保质期后时间还不能到达订单时间(队首的时间太早了)，队首出队
                sum += (q[h].num + S * (i - q[h].time)) * order[p++].num; // 采用时间最早的状态
            }
        }
        printf("%lld\n", sum);
    }
    return 0;
}